# -*- coding: utf-8 -*-

import os

from tornado.options import options
from tornado.options import define
from tornado import ioloop

from odb import utils

def main():
    define("base_path", help="the base path for syncing")

    define("private_key", os.path.expanduser("~/.ssh/id_dsa"),
       help="Path to private key")
    define("ident", default=os.uname()[1], help="Represents the username")
    define("port", default=8080, help="Port where our server should listen on",
       type=int)

    try:
        options.enable_pretty_logging()
    except:
        utils.logger.info("Pretty logging disabled.")

    from odb import peer

    # setting up the own peer
    utils.logger.info('Setting up peer with ident %s listening on port %i' %
                 (options.ident, options.port))
    key = open(options.private_key).read()
    me = peer.Peer(key, options.ident, port=options.port)
    me.start_secure_server([])

    # starting the ioloop
    ioloop.IOLoop.instance().start()
